package com.zh.controller;

import com.zh.pojo.Student;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

@Controller
public class UserController {
    @RequestMapping("/save")
    @ResponseBody
    public void save(String name, Integer age) throws IOException {
        System.out.println(name + "   " + age);
    }

    @RequestMapping("/pojo")
    @ResponseBody
    public String pojo(@RequestBody Student student) throws IOException {
        System.out.println(student);
        return "aaa";
    }

    @RequestMapping("/student")
    @ResponseBody
    public List<Student> student() throws IOException {
        Student s1 = new Student("zh", 26);
        Student s2 = new Student("ls", 25);
        Student s3 = new Student("小张", 21);
        List<Student> list = new ArrayList<Student>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        System.out.println("aaa");
        return list;
    }

    @RequestMapping("/date")
    @ResponseBody
    public void date(Date date,@DateTimeFormat(pattern = "YYYY-MM-dd") Date date1) throws IOException {
        System.out.println(date + "" + date1);
    }

    @RequestMapping("/resp")
    @ResponseBody
    public List<Student> resp() throws IOException {
        List<Student> list = new ArrayList<Student>();
        Student s1 = new Student("小张", 23);
        Student s2 = new Student("小王", 24);
        list.add(s1);
        list.add(s2);
        for (Student student : list) {
            System.out.println(student);
        }
        return list;
    }

}
